import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String a[]= s.split("；");
        int sum = 0;
        String c[];
        TreeSet<Book> ts = new TreeSet<Book>();

        for(String b:a) {
            c = b.split(":");
            Book book = new Book(c[0], Integer.parseInt(c[1]));
            sum += Integer.parseInt(c[1]);
            ts.add(book);
        }
            for (Book book: ts){
                System.out.println(book);
            }

            System.out.println(sum);

    }
}
class Book implements Comparable {
    String name;
    int price;

    public Book(String name, int price) {
        this.name = name;
        this.price = price;
    }

    public int compareTo(Object o) {
        Book b = (Book) o;
        return this.price - b.price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}


